package com.hitrust.gs.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletOutputStream;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;

public class GsProviderScanQueryImportTemplateDownloadAction extends GSBaseAction {

	public String execute(GSBaseForm aForm) throws Exception {
		InputStream is = null;
		HSSFWorkbook workbook = null;
		ServletOutputStream out = null;
		try {
			is = new FileInputStream(aForm.getRequest().getRealPath("") + File.separator + "importProviderTemplate.xls");
			workbook = new HSSFWorkbook(is);
			
			 aForm.getResponse().setContentType("application/ms-excel");
	    	 aForm.getResponse().setHeader("Content-disposition", "attachment; filename=" + "ProviderModifyTemplate.xls");
	    	 out = aForm.getResponse().getOutputStream();
	    	 workbook.write(out);
		} catch (Exception e) {
			
		}finally{
			try {
				if (is != null){
					is.close();
				}
				
				if (out != null){
					out.flush();
					out.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

}
